import request from '@/utils/request'

// 查询生成表数据
export function listTable(query) {
  return request({
    // url: '/tool/gen/list',
    url: '/code/gen2/list',
    method: 'get',
    params: query
  })
}
// 查询db数据库列表
export function listDbTable(query) {
  console.log({query})
  return request({
    // url: '/tool/gen/db/list',
    url: '/code/gen2/db/list',
    method: 'get',
    params: query
  })
}

// 查询表详细信息
export function getGenTable(tableId,dsname) {
  const urlParam = dsname?`?dsname=${dsname}`:'';
  const url = `/code/gen2/${tableId}${urlParam}`;  
  return request({
    // url: '/tool/gen/' + tableId,
    // url: '/code/gen2/' + tableId,
    url: url,
    method: 'get'
  })
}

// 修改代码生成信息
export function updateGenTable(data) {
  return request({
    // url: '/tool/gen',
    url: '/code/gen2',
    method: 'put',
    data: data
  })
}

// 导入表
export function importTable(data) {
  console.log({data})
  return request({
    // url: '/tool/gen/importTable',
    url: '/code/gen2/importTable',
    method: 'post',
    params: data
  })
}

// 创建表
export function createTable(data) {
  return request({
    // url: '/tool/gen/createTable',
    url: '/code/gen2/createTable',
    method: 'post',
    params: data
  })
}

// 预览生成代码
export function previewTable(tableId,dsname) {
  const urlParam = dsname?`?dsname=${dsname}`:'';
  const url = `/code/gen2/preview/${tableId}${urlParam}`;
  console.log({url})
  return request({
    // url: '/tool/gen/preview/' + tableId,
    // url: '/code/gen2/preview/' + tableId,
    url: url,
    method: 'get'
  })
}

// 删除表数据
export function delTable(tableId, dsname) {
  const urlParam = dsname?`?dsname=${dsname}`:'';
  const url = `/code/gen2/${tableId}${urlParam}`;
  
  console.log({url});
  return request({
    // url: '/tool/gen/' + tableId,
    url: url,
    method: 'delete'
  })
}

// 生成代码（自定义路径）
export function genCode(tableName,dsname) {
  const urlParam = dsname?`?dsname=${dsname}`:'';
  const url = `/code/gen2/genCode/${tableName}${urlParam}`;    
  return request({
    // url: '/tool/gen/genCode/' + tableName,
    // url: '/code/gen2/genCode/' + tableName,
    url: url,
    method: 'get'
  })
}

// 同步数据库
export function synchDb(tableName,dsname) {
  const urlParam = dsname?`?dsname=${dsname}`:'';
  const url = `/code/gen2/synchDb/${tableName}${urlParam}`;  
  return request({
    // url: '/tool/gen/synchDb/' + tableName,
    // url: '/code/gen2/synchDb/' + tableName,
    url: url,
    method: 'get'
  })
}
